package com.sntk.organauthomanager;

import com.sntk.organauthomanager.application.quartz.HeartbeatDetectionJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Date;

/**
 * @ClassName: QuartzConfig
 * @author: wgchao
 * @createTime: 2020/8/13 2:04 PM
 * @Description: TODO
 */
//@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail myJobDetail(){
        JobDetail jobDetail = JobBuilder.newJob(HeartbeatDetectionJob.class)
                .withIdentity("heartbeatDetectionJob")
                .storeDurably()
                .build();
        return jobDetail;
    }
    @Bean
    public Trigger myTrigger(){
        Trigger trigger = TriggerBuilder.newTrigger()
                .forJob(myJobDetail())
                .withIdentity("careList")
                //检测从项目启动五分钟之后开始
                .startAt(new Date(System.currentTimeMillis() + 300000))
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0/5 * * * ?"))//每五分钟执行一次
                .build();
        return trigger;
    }
}
